#include <iostream>
#include <string>
#include <stdexcept>
#include "SDL.h"
#include "sdlevent.h"
using namespace std;

void SDLEvent::Poll() throw(sdlevent_error)
{
       key_ = "";
       left_click_ = false;
       mouse_x_ = 0;
       mouse_y_ = 0;

       while(SDL_PollEvent(&event))
       {
	      switch(event.type)
	      {
	      case SDL_KEYDOWN:
		     key_ = SDL_GetKeyName(event.key.keysym.sym);
		     break;
	      case SDL_QUIT:
		     key_ = "SDL_QUIT";
		     break;
	      case SDL_MOUSEBUTTONDOWN:
		     if(event.button.button == SDL_BUTTON_LEFT)
		     {
			    left_click_ = true;
			    mouse_x_ = event.motion.x;
			    mouse_y_ = event.motion.y;
		     }


	      }
       }
}

std::string SDLEvent::GetKey() throw(sdlevent_error)
{
       return key_;
}

bool SDLEvent::mouse_clicked() throw(sdlevent_error)
{
       return left_click_;
}

int SDLEvent::GetMouseX() throw(sdlevent_error)
{
       return mouse_x_;
}

int SDLEvent::GetMouseY() throw(sdlevent_error)
{
       return mouse_y_;
}
